﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using Ingebet.Model.Domain;

namespace Ingebet.Utils
{
    public class XmlHelper
    {
        public static List<VueMatch> XmlToListMatch(string fluxRss)
        {
            List<VueMatch> lstMatch = new List<VueMatch>();

            XElement xelement = XElement.Load(fluxRss);

            var reqLstMatch = from item in xelement.Descendants("item")
                              select new VueMatch
                              {
                                  Competition = item.Element("ligue").Value,
                                  Equipe1 = (item.Element("match").Value.Split(new char[] { '-' }))[0],
                                  Equipe2 = (item.Element("match").Value.Split(new char[] { '-' }))[1],
                                  DateMatch = DateTime.ParseExact(item.Element("matchDate").Value,
                                                                  "yyyy-MM-dd HH:mm:ss",
                                                                   CultureInfo.InvariantCulture),
                                  Description = item.Element("description").Value
                              };

            foreach (var match in reqLstMatch)
            {
                lstMatch.Add(match);
            }

            return lstMatch;
        }
    }
}